package seeders

import (
	"encoding/json"

	"hyper/app/Models"
	"hyper/supports/database"
)

func PermissionSeeder() {
	// 获取所有的菜单
	menus := getMenuAll()
	// 获取所有角色
	roles := getRoleAll()
	// 添加权限
	//if !Models.IsExist() {
	for _, val := range roles {
		for _, value := range menus {
			_permission := []Models.Permission{
				{
					RoleId: val.ID,
					MenuId: value.ID,
					// Authority: `["index","create","store","edit","update","destroy","show"]`,
				},
			}
			database.DB.Create(&_permission)
		}
	}
	//}
}
func getRoleAll() (roles []Models.Role) {
	database.DB.Model(&Models.Role{}).Find(&roles)
	return
}

func getMenuAll() (menu []Models.MenuList) {
	database.DB.Model(&Models.Menu{}).Find(&menu)
	return
}

func method() string {
	str := `["index","create","store","edit","update","destroy","show"]`
	send, _ := json.Marshal(str)
	return string(send)
}
